//
//  NewsCustomCell.m
//  AppYing
//
//  Created by DD on 14-10-30.
//  Copyright (c) 2014年 appying_wxj. All rights reserved.
//

#import "NewsCustomCell.h"

@implementation NewsCustomCell
@synthesize backgroundView,titleLabel,line,imageView,contentLabel,shareButton,collectButton,messageButton,heatLabel,footImageView;

-(instancetype)initWithStyle:(UITableViewCellStyle)cellStyle reuseIdentifier:(NSString *)indentifier
{
    self = [super initWithStyle:cellStyle reuseIdentifier:indentifier];
    if (self)
    {
        //背景
        backgroundView = [[UIView alloc] init];
        backgroundView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backgroundView];
        
        // 文章的标题
        titleLabel = [[UILabel alloc] init];
        titleLabel.numberOfLines = 2;
        titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.font = [UIFont systemFontOfSize:16];
        [backgroundView addSubview:titleLabel];
        
        // 分割的线
        line = [[UIView alloc] init];
        line.backgroundColor = [UIColor lightGrayColor];
        [titleLabel addSubview:line];
        
        // 文章的图片
        imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"image_keji@2x.jpg"];
        imageView.userInteractionEnabled = YES;
        [backgroundView addSubview:imageView];
        
        // 文章内容的label
        contentLabel = [[UILabel alloc] init];
        [backgroundView addSubview:contentLabel];
        
        
    
        // 最底部的view
        footImageView = [[UIImageView alloc] init];
        footImageView.frame = CGRectMake(10, 295, 300, 45);
        footImageView.userInteractionEnabled = YES;
        footImageView.image = [UIImage imageNamed:@"image_mainPinglun@2x"];
        [self addSubview:footImageView];

        // 分享的按钮
        shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        shareButton.backgroundColor = [UIColor clearColor];
        shareButton.frame = CGRectMake(kScreen_Width-10-45-45, 295, 45, 45);
        [self addSubview:shareButton];
        
        // 收藏按钮
        collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        collectButton.frame = CGRectMake(kScreen_Width-10-45, 295, 45, 45);
        
        collectButton.backgroundColor = [UIColor clearColor];
        [self addSubview:collectButton];
        
        // 信息按钮
        messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        messageButton.backgroundColor = [UIColor clearColor];
        messageButton.frame = CGRectMake(kScreen_Width-10-45-45-45, 295, 45, 45);
        [self addSubview:messageButton];
        
        // 底部view上的UILabel
        heatLabel = [[UILabel alloc] init];
        heatLabel.text = @"3215热度";
        heatLabel.textColor = [UIColor colorWithRed:0.63 green:0.64 blue:0.65 alpha:1];
        heatLabel.frame = CGRectMake(45, 305, 105, 30);
        heatLabel.textAlignment = NSTextAlignmentCenter;
        heatLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:heatLabel];

    }
    return self;
}


-(void)layoutCell:(NSDictionary *)aNewsDic
{
    NSString *str = @"触控今天给了大家很多的开发框架，有cocos2d-x，cocos2d-js，quick等。如果要跨浏览器可以用cocos2d-js";
    CGSize size = [self theWordSize:str withFont:16];
    titleLabel.frame = CGRectMake(10, 5, self.bounds.size.width-40, size.height);
    titleLabel.text = str;
    line.frame = CGRectMake(0, titleLabel.bounds.size.height-5, titleLabel.bounds.size.width, 0.5);
    
    backgroundView.frame = CGRectMake(10, 10, kScreen_Width-20, 330);
    
    imageView.frame = CGRectMake(10, size.height+10, self.bounds.size.width-40, size.height+70);
  
    

   
    contentLabel.frame = CGRectMake(10, 130, kScreen_Width-40,60);
    
    
    
}
- (CGSize)theWordSize:(NSString *)str withFont:(CGFloat)afont
{
    
    CGSize size;
    UIFont *font=[UIFont systemFontOfSize:afont];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
        size =[str boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
    } else {
        size = [str sizeWithFont:font constrainedToSize:CGSizeMake(MAXFLOAT, 30) lineBreakMode:NSLineBreakByCharWrapping];
    }
    return size;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
